package com.wxCompany;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        String url ="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9660791c-3c8d-4451-944c-65993ff31feb";
        String text = "{\"success\":null,\"data\":{\"success\":false,\"code\":403,\"message\":\"传感器未安装在轮位上\"},\"message\":\"传感器未安装在轮位上\",\"status\":400,\"code\":\"403\"}";
        String path = " https://open-p.zhilunkeji.com/open/api/wheels/opt/uninstallSensorNo?accessKey=ade0ccb442c945fb939a2f82193f6cdf&timestamp=1725499947&sign=36b006f3d36cf4dbba3526f36c76e270";
//        String ip = "192.168.1.1";
        String req = "{\"sensorNo\":\"22149932\",\"operator\":\"黄超凡\"}\n";
        
        // 获取当前时间，并格式化为 "yyyy-MM-dd HH:mm:ss"
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        
        // 格式化字符串，构建 JSON 字符串
        // 使用 String.format 来构建正确的 JSON 字符串，注意双引号的转义
        String param = String.format("{\"msgtype\": \"markdown\", " +
                        "\"markdown\": {\"content\": \"" +
                        "异常：<font color=\\\"warning\\\">%s</font>\\n" +
                        "请求地址：<font color=\\\"info\\\">%s</font>\\n" +
//      "ip：<font color=\\\"info\\\">%s</font>\\n" +
                        "请求参数：<font color=\\\"info\\\">%s</font>\\n" +
                        "时间：%s\"}}",
                text, path, req, time);


        HttpRequest request = HttpUtil.createPost(url).body(param);



        System.out.println("body: " );
        System.out.println(param);
        // 执行请求并获取响应
        HttpResponse response = request.execute();

        // 获取响应结果
        String result = response.body();
        System.out.println("Response: " );
        System.out.println(result);
    }
}
